package com.teemor.blog.api;

/**
 * @ename zhoulk
 * @cname 周李科
 * @date 2020/11/24 12:03
 */
public class Test {

    public static void main(String[] args) {

         System.out.println(jump(new int[] {0}));

    }


    public static int jump(int[] nums) {
        if (nums==null || nums.length==0 || nums[0] ==0) return 0;
        if (nums.length <=2) return 1;

        int num =0, max = 0, end = 0;

        for (int i=0;i<nums.length-1; i++) {
            int step = nums[i];
            max = Math.max(max, i + step);
            if (max == nums.length) {
                num +=1;
                return num;
            }
            if (end == i) {
                num+=1;
                end = max;
            }
        }
        return num;
    }
}
